package com.springboot.java.design.flyweignt;

import java.util.HashMap;

/**
 * @Author: TongRui乀
 * @Date: 2019-12-13 13:44
 * @description：   享元池  单例模式
 */
public class GoChessmanFactory {

    private static GoChessmanFactory instance = new GoChessmanFactory();

    private HashMap<String, IGoChessman> pool;

    private GoChessmanFactory(){

        pool = new HashMap<>();

        pool.put("white", new WhiteGoChessman());

        pool.put("black", new BlackGoChessman());
    }

    public static GoChessmanFactory getInstance(){
        return instance;
    }

    public IGoChessman getGoChessman(String key){
        if(pool.containsKey(key)){
            return pool.get(key);
        }
        return null;
    }

}
